package com.huanglj.taobaounion.view.customView;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import com.huanglj.taobaounion.utils.LogUtil;


public class LoopViewPager extends ViewPager {

    boolean isTrue = false;
    private Handler mHandler;
    private static final String TAG = "LoopViewPager";

    public LoopViewPager(@NonNull Context context) {
        this(context,null);
    }

    public LoopViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LogUtil.d(TAG,"onCreate");
        mHandler = new Handler(Looper.getMainLooper());
    }

    public void startLooper(){
        isRun = true;
        removeCallbacks(mTask);
        LogUtil.d(TAG,"start");
        mHandler.postDelayed(mTask,3000);
    }
    boolean isRun = false;
    private Runnable mTask = new Runnable() {
        @Override
        public void run() {
            int currentItem = getCurrentItem();

            currentItem++;
            setCurrentItem(currentItem);
            postDelayed( this,3000);
        }
    };
    public void stopLooper(){
        isRun = false;
        LogUtil.d(TAG,"stop");
        mHandler.removeCallbacks(mTask);}


}
